<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master"Inherits="System.Web.Mvc.ViewPage<DIS_WEB_Client.ViewModels.GroupViewModel>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	SelectWeeklyReport
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent1" runat="server">
	<span class="AdminTitle" style="color:#cc0000;">WeeklyReport Management</span>
	(<a href="<%= Url.Action("Index", "Home") %>" class="AdminPageText">
		<%= WebConfiguration.SiteName  %>
	</a>|
	<a href="<%= Url.Action("LogOff", "Account") %>" class="AdminPageText">
		LogOut
	</a>)
	<br />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent2" runat="server">
	<script type="text/javascript">
		$(document).ready(function () {
			$("#WeeklyReport_StartDate").datepicker();
			$("#WeeklyReport_EndDate").datepicker();
		});
		<% if (Model.WeeklyReportModel.InfoText != null && Model.WeeklyReportModel.InfoText != ""){ %>
			alert('<%= Model.WeeklyReportModel.InfoText %>');
		<% } %>

        function ValidateWeeklyReport() {
	        var startdate = document.getElementsByName("WeeklyReport_StartDate").item(0);
	        if (startdate.value == "") {
		        alert("Please input StartDate");
		        return false;
	        }
	        var enddate = document.getElementsByName("WeeklyReport_EndDate").item(0);
	        if (enddate.value == "") {
		        alert("Please input EndDate");
		        return false;
	        }

            var startDateVal = new Date(eval('"' + startdate.value + '"'));
            var endDateVal = new Date(eval('"' + enddate.value + '"'));

            if (startDateVal.getDay() != 1)
            {
                alert("Start date must be monday");
                return false;
            }
            if (endDateVal.getDay() != 0)
            {
                alert("End date must be sunday");
                return false;
            }
            if (startDateVal > endDateVal)
            {
                alert("Start date larger than end date");
                return false;
            }

            var rangeDate = getDates(startDateVal, endDateVal);
            if (rangeDate.length > 7)
            {
                alert("Start date and end date is not same in a week");
                return false;
            }

	        var note = document.getElementsByName("WeeklyReport_Note").item(0);
	        if (note.value == "") {
		        alert("Please choose Note");
		        return false;
	        }
	        return true;
        }

        Date.prototype.addDays = function(days) {
           var dat = new Date(this.valueOf())
           dat.setDate(dat.getDate() + days);
           return dat;
        }

        function getDates(startDate, stopDate) {
            var dateArray = new Array();
            var currentDate = startDate;
            while (currentDate <= stopDate) {
                dateArray.push( new Date (currentDate) )
                currentDate = currentDate.addDays(1);
            }
            return dateArray;
        }
	</script>
	<div id="PartialDiv">
		<% Html.RenderPartial("Templates/TH_ListWeeklyReport", Model); %>
	</div>
	<% using (Html.BeginForm("InsertWeeklyReport", "Admin", FormMethod.Post, new { onsubmit = "return ValidateWeeklyReport();" }))
	{ %>
		<input type="hidden" name="WeeklyReport_IDChemistWareHouse" value="<%= Model.WeeklyReportModel.ReferKeys.IDChemistWareHouse %>" />
		<div style="padding-top: 40px">
			<span style="font-size:18px; font-weight:bold;">Add New WeeklyReport</span>
			<table width="100%" border="0" cellspacing="0" cellpadding="0" class="AdminPageText">
				<tbody>
					<tr>
						<td>
							<div align="left" style="padding-top:15px">
								<font class="normal8">StartDate: </font>
							</div>
						</td>
						<td height="20">
							<div align="left" style="padding-top:15px">
								<%= Html.TextBox("WeeklyReport_StartDate", "", new { @style = "width: 200px;" })%>
							</div>
						</td>
					</tr>
					<tr>
						<td>
							<div align="left" style="padding-top:15px">
								<font class="normal8">EndDate: </font>
							</div>
						</td>
						<td height="20">
							<div align="left" style="padding-top:15px">
								<%= Html.TextBox("WeeklyReport_EndDate", "", new { @style = "width: 200px;" })%>
							</div>
						</td>
					</tr>
					<tr>
						<td>
							<div align="left" style="padding-top:15px">
								<font class="normal8">Note: </font>
							</div>
						</td>
						<td height="20">
							<div align="left" style="padding-top:15px">
								<%= Html.TextArea("WeeklyReport_Note", "", new { @style = "width: 590px; height: 100px;" })%>
							</div>
						</td>
					</tr>
					<tr>
						<td height="20" style="width: 130px">
						</td>
						<td height="20">
							<div align="left">
								<br/>
								<p>
									<input type="submit" value="Add New" />
								</p>
							</div>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
	<% } %>
</asp:Content>
